/*******************************************************************************
 * Copyright 2011 WaTho
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.wathoserver.android.dragoid.activity.tabs;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import de.wathoserver.android.dragoid.R;
import de.wathoserver.android.dragoid.util.UrlParsingActivity;

/**
 * Stellt die Tabansicht dar und fügt ein Menü hinzu.
 * 
 * @author watho
 * 
 */
public class OverviewActivity extends TabActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.overview);
		Resources res = getResources();
		TabHost tabHost = getTabHost();
		TabHost.TabSpec spec;
		Intent intent;

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, BuildingsActivity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("buildings")
				.setIndicator(res.getText(R.string.buildings))
				.setContent(intent);
		tabHost.addTab(spec);

		// Do the same for the other tabs
		intent = new Intent().setClass(this, StockActivity.class);
		spec = tabHost.newTabSpec("stocks")
				.setIndicator(res.getText(R.string.stock)).setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, ProductionActivity.class);
		spec = tabHost.newTabSpec("production")
				.setIndicator(res.getText(R.string.production))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, MaterialActivity.class);
		spec = tabHost.newTabSpec("material")
				.setIndicator(res.getText(R.string.material))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, ConditionActivity.class);
		spec = tabHost.newTabSpec("condition")
				.setIndicator(res.getText(R.string.condition))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, NoticeActivity.class);
		spec = tabHost.newTabSpec("notice")
				.setIndicator(res.getText(R.string.notice)).setContent(intent);
		tabHost.addTab(spec);
		tabHost.setCurrentTab(0);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.mainmenu, menu);
		return true;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.reload:
			((UrlParsingActivity) getCurrentActivity()).reload();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

}
